home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.555 < prev    next >
Text File  |  1992-02-06  |  2KB  |  66 lines

  1. {\rtf0\ansi{\fonttbl\f2\fnil Times-Roman;\f3\fmodern Courier;\f0\fswiss Helvetica;}
  2. \paperw11760
  3. \paperh7200
  4. \margl120
  5. \margr120
  6. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f2\b0\i0\ul0\fs28 Text ScrollView \
  7.     \
  8. Q:  In my application I have subclassed the Text object and called it SubText.  I have a ScrollView which I installed using IB which has a standard Text object as its docView.  I wish to replace that Text object with my own but I wish to maintain all the same behaviors—with a vertical scrollbar and text which resizes properly.  How do I do that?\
  9.  
  10. \i     \
  11.  
  12. \i0 A:  The following code snippet will create an instance of your new subclass of Text and will insert it into the docView of the ScrollView. The old Text object is then freed. In the code sample ``theSV'' is an outlet connected to the ScrollView. Because an existing ScrollView is used, certain setups are not required. See Chapter 9, page 35 of the Concepts volume of the 1.0 Technical Documentation for more information on setting up a brand-new ScrollView.\
  13. \
  14. The key here that many people miss is to set the min size and max size on the Text object.\
  15. \
  16.  
  17. \f3\fs24     id    stdDoc;\
  18.     NXRect    r;\
  19.     \
  20.     /* Measure the old doc view. */\
  21.     stdDoc = [theSV docView];\
  22.     [stdDoc getFrame:&r];\
  23. \
  24.     [theSV setVertScrollerRequired:YES];\
  25.     [theSV setHorizScrollerRequired:NO];\
  26.     [theSV setDynamicScrolling:YES]; \
  27.     \
  28.     /* Instantiate the new Text object */\
  29.  
  30. \b #ifdef 1.0\
  31.  
  32. \b0     newDoc = [SubText newFrame:&r];\
  33.  
  34. \b #else  /* 2.0 */\
  35.  
  36. \b0     newDoc = [[SubText alloc] initFrame: &r];\
  37.  
  38. \b #endif\
  39.  
  40. \b0     [newDoc moveTo:0.0:0.0];\
  41.     [newDoc notifyAncestorWhenFrameChanged: YES];\
  42.     [newDoc setVertResizable:YES];\
  43.     [newDoc setSelectable:YES];\
  44.     [newDoc setEditable: YES];\
  45.     [newDoc setAutosizing:NX_WIDTHSIZABLE];\
  46.     [newDoc setMinSize:&r.size];\
  47.     r.size.height = 1.0e30;\
  48.     [newDoc setMaxSize:&r.size];\
  49.     [theSV setDocView:newDoc];\
  50.     \
  51.     /* Free the old Text object */\
  52.     [stdDoc free];\
  53.     \
  54.     
  55. \f2\fs28 \
  56.  
  57. \b Note that the ifdef for 1.0 is for illustration purposes only and is NOT defined in any NeXTstep include file.\
  58.  
  59. \b0 \
  60. QA555    \
  61. \
  62. Valid for 1.0\
  63. Valid for 2.0  (with the differences noted)        \
  64. \
  65.  
  66.